package com.woniuxy01;

/**
 * @author 作者
 * @create 2025-09-04 9:52
 */
public class Student {
    //成员变量一般私有
    private String name;
    private int age;

    //构造方法一般公有
    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //其他类不能够直接访问属性，通过一组getXxx()setXxx()来间接操作
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }

    public int getAge(){
        return age;
    }

    public void setAge(int age){
        if (age>=0 &&age<=120) {
            this.age = age;
        }else{
            this.age=18;
        }
    }


    public String show(){
        return "name="+name+",age="+age;
    }
}
